package Frames;

import Entidades.Usuario;
import java.beans.PropertyVetoException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.UnsupportedLookAndFeelException;

public class FrmPrincipal extends javax.swing.JFrame {
    
    Usuario usuario;
    JDesktopPane desktop;
    private JInternalFrame frmLancaEntrada;
    private JInternalFrame frmLancaSaida;
    private JInternalFrame frmManterEntrada;
    int contador1 = 0;
    int contador2 = 0;
    int contador3 = 0;

    public FrmPrincipal(Usuario usuario) {
        this.usuario = usuario;
        lookAndFill();
        initComponents();
        desktop = new JDesktopPane();
        setContentPane(desktop);
        setExtendedState(MAXIMIZED_BOTH);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mbPrincipal = new javax.swing.JMenuBar();
        mTesouraria = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        miLancarEntrada = new javax.swing.JMenuItem();
        miManterEntrada = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenu2 = new javax.swing.JMenu();
        miLancarSaida = new javax.swing.JMenuItem();
        mOpcoes = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SisConE - Sistema de Controle Eclesiástico");
        setBackground(new java.awt.Color(255, 255, 255));

        mbPrincipal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        mbPrincipal.setMaximumSize(new java.awt.Dimension(100, 32769));
        mbPrincipal.setMinimumSize(new java.awt.Dimension(100, 21));
        mbPrincipal.setPreferredSize(new java.awt.Dimension(112, 30));

        mTesouraria.setText("Tesouraria");

        jMenu1.setText("Entradas");

        miLancarEntrada.setText("Lançar Entrada");
        miLancarEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLancarEntradaActionPerformed(evt);
            }
        });
        jMenu1.add(miLancarEntrada);

        miManterEntrada.setText("Manter Entrada");
        miManterEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miManterEntradaActionPerformed(evt);
            }
        });
        jMenu1.add(miManterEntrada);

        mTesouraria.add(jMenu1);
        mTesouraria.add(jSeparator1);

        jMenu2.setText("Saidas");

        miLancarSaida.setText("Lançar Saída");
        miLancarSaida.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                miLancarSaidaActionPerformed(evt);
            }
        });
        jMenu2.add(miLancarSaida);

        mTesouraria.add(jMenu2);

        mbPrincipal.add(mTesouraria);

        mOpcoes.setText("Opções");
        mbPrincipal.add(mOpcoes);

        setJMenuBar(mbPrincipal);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 735, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 474, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void miLancarEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLancarEntradaActionPerformed
        if(frmLancaEntrada instanceof IfrmLancarEntrada && frmLancaEntrada.isVisible()) {
            frmLancaEntrada.moveToFront();
            try {
                frmLancaEntrada.setSelected(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            return;
        }
        frmLancaEntrada = new IfrmLancarEntrada(usuario);
        desktop.add(frmLancaEntrada);
        frmLancaEntrada.setVisible(true);
        contador1++;
        frmLancaEntrada.setTitle("Lançar Entrada "+contador1);
    }//GEN-LAST:event_miLancarEntradaActionPerformed

    private void miLancarSaidaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miLancarSaidaActionPerformed
        if(frmLancaSaida instanceof IfrmLancarSaida && frmLancaSaida.isVisible()) {
            frmLancaSaida.moveToFront();
            try {
                frmLancaSaida.setSelected(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            return;
        }
        frmLancaSaida = new IfrmLancarSaida(usuario);
        desktop.add(frmLancaSaida);
        frmLancaSaida.setVisible(true);
        contador2++;
        frmLancaSaida.setTitle("Lançar Saída "+contador2);        
    }//GEN-LAST:event_miLancarSaidaActionPerformed

    private void miManterEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miManterEntradaActionPerformed
        if(frmManterEntrada instanceof IfrmManterEntrada && frmManterEntrada.isVisible()) {
            frmManterEntrada.moveToFront();
            try {
                frmManterEntrada.setSelected(true);
            } catch (PropertyVetoException ex) {
                Logger.getLogger(FrmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
            }
            return;
        }
        frmManterEntrada = new IfrmManterEntrada(usuario);
        desktop.add(frmManterEntrada);
        frmManterEntrada.setVisible(true);
        contador3++;
        frmManterEntrada.setTitle("Manter Entrada "+contador3);
    }//GEN-LAST:event_miManterEntradaActionPerformed

    public static void lookAndFill(){
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {                
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                } else {
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }        
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenu mOpcoes;
    private javax.swing.JMenu mTesouraria;
    private javax.swing.JMenuBar mbPrincipal;
    private javax.swing.JMenuItem miLancarEntrada;
    private javax.swing.JMenuItem miLancarSaida;
    private javax.swing.JMenuItem miManterEntrada;
    // End of variables declaration//GEN-END:variables
}
